#include <stdio.h>
#include <iostream>

using namespace std;

int main()
{
  int buffer, subtotal = 0, total = 0;
  int last_input = -1;
  while(1)
  {
    cout << "Please enter an integer: ";
    cin >> buffer;
    if(buffer == 0)
    {
      if (last_input == 0)
      {
        cout << "Total = " << total << endl;
        break;
      } 
      cout << "Subtotal = " << subtotal << endl;
      total += subtotal;
      subtotal = 0;
    }
    else
    {
      subtotal += buffer;
    }
    last_input = buffer;
  }
  return 0;
}
